<?php
    define('IN_ECS', true);
    require(dirname(__FILE__) . '/includes/init.php');
    $act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
    if($act == 'tipword'){
        include_once('includes/cls_json.php');
        $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
        $json  = new JSON;
        $word = isset($_REQUEST['word']) ? $_REQUEST['word'] : '';
        if($word!=''){
            $arr = array();
            /* 检查关键字中是否有空格，如果存在就是并 */
            $keyword = preg_replace('/ +/',' ',$word);
            $arr        = explode(' ', $keyword);
            $operator   = " AND ";
            $keywords = 'AND (';
            $chinese = 'AND (';
            foreach ($arr AS $key => $val)
            {
                if ($key > 0 && $key < count($arr) && count($arr) > 1)
                {
                    $keywords .= $operator;
                    $chinese .=$operator;
                }
                $val        = mysql_like_quote(trim($val));
                $goods_name .=$val;
                $keywords  .= "(keywords LIKE '%$val%' )";
                $chinese  .= "(chinese LIKE '%$val%' )";
            }
            $keywords .= ')';
            $chinese .= ')';
            $sql = "select * from".$ecs->table('user_search')."where 1=1 ".$keywords." or 2=2 ".$chinese;
            $row = $db->getAll($sql);
            $count = count($row);
            $smarty -> assign('data',$row);
            $smarty -> assign('num',$count);
        }
        $result['error'] = 0;
        $result['content']= $smarty->fetch('library/gc_search.lbi');
        die($json->encode($result));
    }
?>